package com.lord.otter.component.test;

import com.lord.otter.component.infrastructure.retry.HttpRetryClient;
import com.lord.otter.component.infrastructure.retry.HttpRetryClientFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/err")
public class ErrTestController {

    @PostMapping("/timeout")
    public void timeout() throws InterruptedException {
        try {
            Thread.sleep(60 * 1000);
        } catch (InterruptedException e) {
            throw e;
        }
    }

    @PostMapping("/test")
    public void test() throws InterruptedException {
        HttpRetryClient client = HttpRetryClientFactory.defaultClient(
                TestBusinessGroup.TEST_GROUP,
                "TEST_BUSINESS_ID",
                "http://127.0.0.1:8080/err/timeout"
        );
        client.execute(HttpMethod.POST);
    }
}
